There are two ways to get Clazz1, Method one:1, the Clazz is declared as a protected modifier, which can be accessed in the class.2, the value of this property is passed in the constructor method of each subclass, such as:Public Roledaoimpl () {clazz = Role.class;}Public Userdaoimpl () {clazz = User.class;}2, method Two: Using the way of reflection:1, write the f
Fastjson This toolkit helps us to convert between Java objects and JSON-formatted strings. The process of object-to-string, which we call serialization, is, conversely, called deserialization.Now let's talk about the deserialization method provided by Fastjson, this article only discusses the deserialization method of returning the corresponding object according to the specified bytecode, which has many overloaded forms, which are designed according to the overlapping pattern. Common entries are
exception");
} st = null;
} if (conn!= null) {try {conn.close ();
catch (Exception e) {throw new RuntimeException ("Connection shutdown exception");
} conn = null; }/** * * * @param clazz * BYTE code * @param ID of the type to be returned * to find the ID of the record in the table * @return Find in the database To the record, and return */public static;
T> T FindByID (class3, the test code is as follows
Package com.jdbc.genericity.test
Reprint please indicate the source:http://blog.csdn.net/sinat_15877283/article/details/50971262;This article comes from: "Winledon's Blog"
Generics are often used in our framing frameworks, and we know that generics have the benefit of checking type
, and thousands of lines are more, therefore, there is a large public library in our front-end application, but each page has to write an external javascript file for corresponding business processing, the following is the basic structure of javascript code writing for this project: copy the code var opts = {version: "1.0.0", name: "sharpxiajun"}; (function (opts) {function Clazz () {return this. init (arguments);}
]. _ functions __)){
CreateMethod. call (self, key, base [key], true );
} Else {
If (key in self ){
// Record rewrite Information
Self [key]. _ overridden _ = base [key];
} Else {
Self [key] = base [key];
}
}
} Else if (! (Key in self )){
Self [key] = base [key];
}
}
}
}
Return function (){
// Processing Parameters
If (this. Type this. Type. type = 'package '){
If (arguments. length = 2 ){
Var name = arguments [0];
Var body = arguments [1];
} Else {
Var name = arguments [0];
Var config = argume
The following table is available: selects. id, s. name, s. grade, s. clazz, s. scorefromstudentsorderbyid1.rollupgroupbyrollup (column1, column2 ....) if groupbyrollup (A, B, C), first perform groupby on A, B, C, then perform groupby On A, B, then perform groupby On A, and finally do not group
The following table is available: select s. id, s. name, s. grade, s. clazz, s. score from student s order by id 1.
Tomcat class loader has three class implementations: standardclassloader, webappclassloader, and jasperloader. These three class loaders are subclasses of urlclassloader. The difference is that standardclassloader does not customize the urlclassloader method, that is, it also uses the delegate method to load classes. The loadclass () method is overwritten.
1. The standardclassloader Class Loader creates an instance of the common class loader.
2. webappclassloader creates a Class Loader instance
the example of Standardclassloader, the following standardclassloader for the source of the explanation.Then look at the creation process of WebappClassLoader, WebappClassLoader is instantiated in the Createclassloader method in the Webapploader class by reflection. Below is the source code: Private WebappClassLoader Createclassloader () throws Exception { Class clazz = Class.forName (Loaderclass);// loaderclass= "Org.apache.catalina
) System. out. println (s) ;}} enum Gender {Male, Female}
No-argument constructor of the reflection class:
@ Test // The non-argument constructor of the reflection Class public void constructor1 () throws Exception {Class clazz = Class. forName ("pro. shaowei. reflect. person "); Constructor c = clazz. getConstructor (); Person p = (Person) c. newInstance (); Person p1 = (Person)
Parameters
If (this. Type this. Type. type = 'package '){
If (arguments. length = 2 ){
Var name = arguments [0];
Var body = arguments [1];
} Else {
Var name = arguments [0];
Var config = arguments [1];
Var body = arguments [2];
}
} Else {
If (arguments. length = 1 ){
Var name = 'anonus us ';
Var body = arguments [0];
} Else {
Var name = 'anonus us ';
Var config = arguments [0];
Var body = arguments [1];
}
}
// Create basic functions of the class
Var
(String str, int i) {System.out.format ("Classmethod::callinstancemethod called!--> str=%s, "+" i=%d\n ", str, i);}}header files generated by Accessmethod.class:/* Don't EDIT this file-it are machine generated */#include the implementation of the function prototype in the local code header file:Accessmethod.c#include "Com_study_jnilearn_accessmethod.h"/* * Class:com_study_jnilearn_accessmethod * Method: Calljavastaticmethod * Signature: () V */jniexport void Jnicall java_com_study_jnilearn_acce
the getclass method.
2: each data type (basic data type and referenced data type) has a static attribute class. Disadvantages: You must specify this class first.
The first two methods are not conducive to program expansion, because they both need to be completed using specific classes in the program.
3: The method in the class used, the static forname method.
If you specify a class name, you can obtain the class bytecode file object. This method has the strongest scalability. You only need to p
getContextObject();......}Here we can see that BinderInternal. getContextObject is a JNI method, which is implemented as follows:~ /Android/frameworks/base/core/jni---- Android_util_Binder.cppstatic jobject android_os_BinderInternal_getContextObject(JNIEnv* env, jobject clazz){ sp
b = ProcessState::self()->getContextObject(NULL); return javaObjectForIBinder(env, b);}
The familiar ProcessState: self ()-> getContextObject function return
ref) (REF) OBJ). OBJ = This. OBJ;
}
@ Override
Public int hashcode (){
Return obj. hashcode ();
}
}
Private list dedup = new arraylist ();
/**
* The memory space occupied by the object. the space occupied by the object is not equal to the size of the object, just like a file in Windows (4 K space occupied when the size is 1 byte)
* @ Param object
* @ Return
*/
Public int occupyof (Object object ){
Dedup. Clear ();
Return occupyof0 (object );
}
Private int occupyof0 (Object object ){
If (Objec
. Disadvantages: You must specify this class first.
The first two methods are not conducive to program expansion, because they both need to be completed using specific classes in the program.
3: Methods in the class used,StaticFornameMethod.
If you specify a class name, you can obtain the class bytecode file object. This method has the strongest scalability. You only need to pass in the class name string.
// 1. Obtain the class used for loading based on the given class name
String classname = "c
to track the "footprint" of objects ". Class is used to access and save the information. There are three methods to obtain the Class. Sample Code:
Package com. reflect. demo; public class ReflectDemo {/** the Java reflection mechanism is in the running state. For any class (class file ), all attributes and methods of this class are available. **/public static void main (String [] args) {System. out. println (createClassDemo_3 (). getName ();} // use the getClass method of the Object Class to ob
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.